<template>
  <button :class="[
    'btn-style',
    {
      'is-small': size === 'small',
      'is-normal': size === 'normal',
      'is-large': size === 'large',
      'is-enlarge': size === 'enlarge',
      'is-maxlarge': size === 'maxlarge',
      'is-primary': type === 'primary',
      'is-success': type === 'success',
      'is-error': type === 'error',
      'is-warn': type === 'warn',
      'is-info': type === 'info',
      'is-disabled': disabled,
      'is-long': long,
      'is-plain': plain,
      'is-round': round,
      'is-circle': circle,
      'is-link': link
    }
  ]" :style="{ backgroundColor: backgroundcolor, width: width, height: height }" :code="code"
    @click="$emit('handleClick')">
    <!-- <i v-if="icon" :class="`${icon}`">
       <img src="../assets/icon-add.png" alt="">
    </i> -->
    <i v-if="icon" class="s-icon">
      <img :src="icon" alt="" :style="{ width: iconwidth, height: iconheight }">
    </i>
    <!-- 如果没传入文本插槽，则不显示span内容 -->
    <span v-if="$slots.default">
      <slot />
    </span>
  </button>
</template>

<script lang="ts" setup>
defineEmits(['handleClick'])
const props = defineProps({
  // size: {
  //   type: String as PropType<sizeType>,
  //   default: ''
  // },
  // type: {
  //   type: String as PropType<btnType>,
  //   default: ''
  // },
  size: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: ''
  },
  disabled: {
    type: Boolean,
    default: false
  },
  long: {
    type: Boolean,
    default: false
  },
  plain: {
    type: Boolean,
    default: false
  },
  round: {
    type: Boolean,
    default: false
  },
  icon: {
    type: String,
    default: ''
  },
  circle: {
    type: Boolean,
    default: false
  },
  link: {
    type: Boolean,
    default: false
  },
  width: {
    type: [Number, String],
    default: ''
  },
  backgroundcolor: {
    type: String,
    default: ''
  },
  height: {
    type: [Number, String],
    default: ''
  },
  code: {
    type: String,
    default: ''
  },
  iconwidth: {
    type: [Number, String],
    default: ''
  },
  iconheight: {
    type: [Number, String],
    default: ''
  }
})

</script>

<style scoped lang="scss">
.btn-style {
  display: inline-block;
  /*变为行内块：*/
  line-height: 1;
  white-space: nowrap;
  /*规定段落中的文本不进行换行：*/
  cursor: pointer;
  background: #ffffff;
  border: 1px solid #dcdfe6;
  color: #606266;
  -webkit-appearance: none;
  /*去除谷歌浏览器自带按钮样式：*/
  text-align: center;
  box-sizing: border-box;
  /*内边距和边框放入宽高内*/
  outline: none;
  /*去除按钮自带边框*/
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  //禁止元素的文字被选中
  -moz-user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
  // width: 70px;
  // height: 40px;

  &:hover,
  &:focus {
    color: #409eff;
    // color: #fff;
    border-color: #c6e2ff;
    background-color: #ecf5ff;
  }

  margin-left: 3px;
  margin-right: 3px;
}

// 按钮尺寸
.btn-style.is-small {
  padding: 6px 14px;

}

.btn-style.is-normal {
  padding: 8px 18px;
}

.btn-style.is-large {
  padding: 10px 32px;
}

.btn-style.is-enlarge {
  padding: 10px 50px;
}

.btn-style.is-maxlarge {
  padding: 10px 82px;
}

//按钮样式
.btn-style.is-primary {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;

  &:hover,
  &:focus {
    background: #66b1ff;
    background-color: #66b1ff;
    color: #fff;
  }
}

.btn-style.is-success {
  color: #fff;
  background-color: #67c23a;
  border-color: #67c23a;

  &:hover,
  &:focus {
    background: #85ce61;
    background-color: #85ce61;
    color: #fff;
  }
}

.btn-style.is-error {
  color: #fff;
  background-color: #f56c6c;
  border-color: #f56c6c;

  &:hover,
  &:focus {
    background: #f78989;
    background-color: #f78989;
    color: #fff;
  }
}

.btn-style.is-warn {
  color: #fff;
  background-color: #e6a23c;
  border-color: #e6a23c;

  &:hover,
  &:focus {
    background: #ebb563;
    background-color: #ebb563;
    color: #fff;
  }
}

.btn-style.is-info {
  color: #fff;
  background-color: #909399;
  border-color: #909399;

  &:hover,
  &:focus {
    background: #a6a9ad;
    background-color: #a6a9ad;
    color: #fff;
  }
}

// 链接样式
.btn-style.is-link {
  border: none !important;

  &:hover,
  &:focus {
    background: none;
  }
}

// 禁用样式
.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

// // 朴素按钮样式
.btn-style.is-plain {

  &:hover,
  &:focus {
    background: #fff;
    border-color: #489eff;
    color: #409eff;
  }
}

.btn-style.is-primary.is-plain {
  color: #409eff;
  background: #ecf5ff;

  &:hover,
  &:focus {
    background: #409eff;
    border-color: #409eff;
    color: #fff;
  }
}

.btn-style.is-success.is-plain {
  color: #67c23a;
  background: #c2e7b0;

  &:hover,
  &:focus {
    background: #67c23a;
    border-color: #67c23a;
    color: #fff;
  }
}

.btn-style.is-info.is-plain {
  color: #909399;
  background: #d3d4d6;

  &:hover,
  &:focus {
    background: #909399;
    border-color: #909399;
    color: #fff;
  }
}

.btn-style.is-warn.is-plain {
  color: #e6a23c;
  background: #f5dab1;

  &:hover,
  &:focus {
    background: #e6a23c;
    border-color: #e6a23c;
    color: #fff;
  }
}

.btn-style.is-error.is-plain {
  color: #f56c6c;
  background: #fbc4c4;

  &:hover,
  &:focus {
    background: #f56c6c;
    border-color: #f56c6c;
    color: #fff;
  }
}

// round样式
.btn-style.is-round {
  border-radius: 20px;
  padding: 12px 23px;
}

// circle样式
.btn-style.is-circle {
  box-sizing: border-box;
  border-radius: 50%;
  padding: 12px;
  padding-right: 14px;
}

// // icon 样式
.btn-style .s-icon {
  // margin-left: -8px;
  box-sizing: border-box;
  // margin-top: 3px;
  // line-height: 1;
}
</style>
